package com.mayikt.zuul.config;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 分布式阿波罗配置中心方法监听
 */
@Slf4j
@Component
public class ApplicationInit implements CommandLineRunner {
    private Logger logger = LoggerFactory.getLogger(ApplicationInit.class);
    @ApolloConfig
    private Config config;
    @Override
    public void run(String... args) throws Exception {
        logger.info("############分布式阿波罗配置中心方法监听启动###########");
        config.addChangeListener(new ConfigChangeListener() {
            @Override
            public void onChange(ConfigChangeEvent configChangeEvent) {
                logger.info("####分布式配置中心监听####"+configChangeEvent.changedKeys().toString());
            }
        });
    }
}
